package es.usal.proyecto.View;

import java.io.IOException;
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


/** A basic Camera preview class */
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
    private SurfaceHolder mHolder;
    private Camera mCamera;
    
    public CameraPreview(Context context,Camera camera) {
        super(context);
        mCamera = camera;
        mHolder = getHolder();
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mHolder.addCallback(this);
        mHolder.setKeepScreenOn(true); 
    }
    
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    	try{
    		mCamera.setPreviewDisplay(holder);
    		mCamera.startPreview(); 
    	} catch (IOException e) {
    		
    	}
    }
     
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h){

    	mCamera.stopPreview();
    	Camera.Parameters parameters = mCamera.getParameters();
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {

    }
    
    
}